<?php


namespace app\common\library;


class PlatformModel {

    static $platforms = null;
    static $citys = null;
    static $appids = null;

    static $wx_profit =[
        '451100' =>[
            'account'=>'1600986333',
            'amount' => 0.3,
            'desc' => '贺州分账'
        ],
        '350800' =>[
            'account'=>'1600817902',
            'amount' => 0.3,
            'desc' => '铜陵分账'
        ],
        '450924' =>[
            'account'=>'1600986333',
            'amount' => 0.3,
            'desc' => '兴业分账'
        ]
    ];

    static $ali_profit =[
        '451100' =>[
            'account'=>'2088831946871474',
            'amount' => 0.3,
            'desc' => '贺州分账'
        ],
        '350800' => [
            'account'=>'2088831940789245',
            'amount' => 0.3,
            'desc' => '铜陵分账'
        ],
        '450924' =>[
            'account'=>'2088831946871474',
            'amount' => 0.3,
            'desc' => '兴业分账'
        ]
    ];

    static function get_platform_info($appid) {
        if (empty(self::$platforms)) {
            self::$platforms = config('app.platforms');
        }

        foreach (self::$platforms as $platform) {
            if ($platform['id'] == $appid) {
                return $platform;
            }
        }
        return null;
    }

    static function get_city_al_token($city_id) {
        if (empty(self::$citys)) {
            self::$citys = config('app.citys');
        }

        $defualt_info = null;
        foreach (self::$citys as $platform) {
            if ($platform['id'] == $city_id) {
                return $platform;
            }

            if ($platform['id'] == 'default'){
                $defualt_info = $platform;
            }
        }
        return $defualt_info;
    }

    static function get_city_profit_share($city_id,$user_id)
    {
        $now = date('Y-m-d H:i:s');
        $begin_time = "2021-02-01 00:00:00";

        if(strtotime($now) - strtotime($begin_time) < 0){
            return false;
        }

        if ($city_id == '451100' || $city_id == '350800'|| $city_id == '450924')
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    static function get_city_profit_config($gate_way,$city_id)
    {
        if (empty($city_id))
            return null;

        if ($gate_way == 'WXPAY'){
            return self::$wx_profit[$city_id];
        }
        elseif ($gate_way == 'ALIPAY'){
            return self::$ali_profit[$city_id];
        }
        else {
            return null;
        }
    }

    static function get_city_profit_list()
    {

    }
}
